package com.ruoyi.web.controller.books;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.books.domain.BooksHistory;
import com.ruoyi.books.service.IBooksHistoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 非遗历史发展Controller
 *
 * @author ruoyi
 * @date 2024-03-27
 */
@Anonymous
@RestController
@RequestMapping("/books/history")
public class BooksHistoryController extends BaseController
{
    @Autowired
    private IBooksHistoryService booksHistoryService;

    /**
     * 查询非遗历史发展列表
     */
//    @PreAuthorize("@ss.hasPermi('books:history:list')")
    @GetMapping("/list")
    public TableDataInfo list(BooksHistory booksHistory)
    {
        startPage();
        List<BooksHistory> list = booksHistoryService.selectBooksHistoryList(booksHistory);
        return getDataTable(list);
    }

    /**
     * 导出非遗历史发展列表
     */
//    @PreAuthorize("@ss.hasPermi('books:history:export')")
    @Log(title = "非遗历史发展", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BooksHistory booksHistory)
    {
        List<BooksHistory> list = booksHistoryService.selectBooksHistoryList(booksHistory);
        ExcelUtil<BooksHistory> util = new ExcelUtil<BooksHistory>(BooksHistory.class);
        util.exportExcel(response, list, "非遗历史发展数据");
    }

    /**
     * 获取非遗历史发展详细信息
     */
//    @PreAuthorize("@ss.hasPermi('books:history:query')")
    @GetMapping(value = "/{historyId}")
    public AjaxResult getInfo(@PathVariable("historyId") Long historyId)
    {
        return success(booksHistoryService.selectBooksHistoryByHistoryId(historyId));
    }

    /**
     * 新增非遗历史发展
     */
//    @PreAuthorize("@ss.hasPermi('books:history:add')")
    @Log(title = "非遗历史发展", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BooksHistory booksHistory)
    {
        return toAjax(booksHistoryService.insertBooksHistory(booksHistory));
    }

    /**
     * 修改非遗历史发展
     */
//    @PreAuthorize("@ss.hasPermi('books:history:edit')")
    @Log(title = "非遗历史发展", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BooksHistory booksHistory)
    {
        return toAjax(booksHistoryService.updateBooksHistory(booksHistory));
    }

    /**
     * 删除非遗历史发展
     */
//    @PreAuthorize("@ss.hasPermi('books:history:remove')")
    @Log(title = "非遗历史发展", businessType = BusinessType.DELETE)
	@DeleteMapping("/{historyIds}")
    public AjaxResult remove(@PathVariable Long[] historyIds)
    {
        return toAjax(booksHistoryService.deleteBooksHistoryByHistoryIds(historyIds));
    }
}
